package com.rzico.order.enumx;

/**
 * Created by icssh on 2020/4/11.
 */
public enum OrderStatusEnum {
    /**
     * 订单状态(0.未确认,1.已确认,2.已完成,3.已取消)
     */
    ORDER_STATUS_UNCONFIRM(0, "未确认"),
    ORDER_STATUS_CONFIRM(1, "已确认"),
    ORDER_STATUS_COMPLETE(2, "已完成"),
    ORDER_STATUS_CANCLE(3, "已取消"),
    ORDER_STATUS_REVIEWED(4, "已评价");

    private Integer id;
    private String name;

    OrderStatusEnum(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    public Integer getId() {
        return this.id;
    }

    public String getName() {
        return this.name;
    }

    public static String getNameById(Integer id){
        if (id == null) {
            return null;
        }
        OrderStatusEnum anEnum = getById(id);
        if (anEnum == null) {
            return null;
        }
        return anEnum.getName();
    }

    public static OrderStatusEnum getById(Integer id) {
        for (OrderStatusEnum anEnum : values()) {
            if (anEnum.getId().equals(id)) {
                return anEnum;
            }
        }
        return null;
    }

    public static void main(String args[]){
        System.out.println(OrderStatusEnum.getNameById(1));
    }
}
